package cn.lili.controller.order;


import cn.lili.common.aop.annotation.PreventDuplicateSubmissions;
import cn.lili.common.enums.ResultCode;
import cn.lili.common.exception.ServiceException;
import cn.lili.common.utils.ResultUtil;
import cn.lili.common.vo.PageVO;
import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.distribution.entity.dto.DistributionApplyDTO;
import cn.lili.modules.distribution.entity.dto.DistributionSearchParams;
import cn.lili.modules.order.order.entity.dos.RankingDistribution;
import cn.lili.modules.order.order.entity.dto.RankingDistributionDTO;
import cn.lili.modules.order.order.entity.vo.RankingDistributionVO;
import cn.lili.modules.order.order.service.IRankingDistributionService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import java.util.List;

/**
 * <p>
 * 排名活动-店主表 前端控制器
 * </p>
 *
 * @author author
 * @since 2023-12-25
 */
@RestController
@Api(tags = "排名活动-店主表接口")
@RequestMapping("/order/ranking_distribution")
@RequiredArgsConstructor
public class RankingDistributionController {

    private final IRankingDistributionService rankingDistributionService;

    @ApiOperation(value = "成为店主-申请店主")
    @PostMapping("/applyDistribution")
    public ResultMessage<Object> applyDistribution(DistributionApplyDTO distributionApplyDTO) {
        return ResultUtil.data(rankingDistributionService.applyDistribution(distributionApplyDTO));
    }


    @ApiOperation(value = "店长审核列表,状态参数:APPLY,RETREAT,REFUSE,PASS")
    @GetMapping
    public ResultMessage<Page<RankingDistribution>> getByPage(DistributionSearchParams distributionSearchParams, PageVO page) {
        return ResultUtil.data(rankingDistributionService.raningDistributionPage(distributionSearchParams, page));
    }

    @ApiOperation(value = "获取当前会员的店主信息", notes = "可根据店主信息查询待提现金额以及冻结金额等信息")
    @GetMapping("/current")
    public ResultMessage<RankingDistribution> getRankingDistribution() {
        return ResultUtil.data(rankingDistributionService.getRankingDistribution());
    }


    @PreventDuplicateSubmissions
    @ApiOperation(value = "审核店长")
    @PutMapping(value = "/audit/{id}")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "店主id", required = true, paramType = "path", dataType = "String"), @ApiImplicitParam(name = "status", value = "审核结果，PASS 通过  REFUSE 拒绝", required = true, paramType = "query", dataType = "String")})
    public ResultMessage<Object> audit(@NotEmpty @PathVariable("id") String id, @NotEmpty String status) {
        if (rankingDistributionService.audit(id, status)) {
            return ResultUtil.success();
        } else {
            throw new ServiceException(ResultCode.RANKING_DISTRIBUTION_AUDIT_ERROR);
        }

    }


    @ApiOperation("等级下拉框数据")
    @GetMapping(value = "/getDistributionLevelList")
    public ResultMessage<List<Object>> getDistributionLevelList() {
        return ResultUtil.data(rankingDistributionService.getDistributionLevelList());
    }

    @ApiOperation(value = "店主排名活动-店主列表")
    @GetMapping(value = "/getRankingStoreList")
    public ResultMessage<Page<RankingDistributionVO>> getRankingStoreList(RankingDistributionDTO dto) {
        return rankingDistributionService.getRankingStoreList(dto);
    }
    @ApiOperation(value = "店家列表-下级人数详情-->下级明细列表")
    @GetMapping(value = "/getLowerDistributeionDetails")
    public ResultMessage<Page<RankingDistributionVO>> getLowerDistributeionDetails(RankingDistributionDTO dto) {
        return rankingDistributionService.getLowerDistributeionDetails(dto);
    }

    @ApiOperation("刷数据")
    @GetMapping(value = "/syncRankingDistributionData")
    public ResultMessage<Object> syncRankingDistributionData() {
        return ResultUtil.data(rankingDistributionService.syncRankingDistributionData());
    }

}
